#pragma once
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <iostream>

class Config {
public:
    static Config& GetInstance() {
        static Config instance;
        return instance;
    }

    Config(const Config&) = delete;
    Config& operator=(const Config&) = delete;

    void InitConfig(const std::string& config) {
        try {
            // 1. 定义一个 PropertyTree 对象
            boost::property_tree::ptree pt;
            // 2. 从文件中解析 INI 配置
            read_ini(config, pt);
            // 3. 读取值
            _server_port = pt.get<int>("Server.Port");
            _server_pool_size = pt.get<int>("Server.PoolSize");
            _redis_host = pt.get<std::string>("Redis.Host");
            _redis_port = pt.get<int>("Redis.Port");
            _redis_password = pt.get<std::string>("Redis.Password", "");
            _redis_pool_size = pt.get<int>("Redis.PoolSize", 5);
            _mysql_host = pt.get<std::string>("Mysql.Host");
            _mysql_port = pt.get<int>("Mysql.Port");
            _mysql_user = pt.get<std::string>("Mysql.User");
            _mysql_password = pt.get<std::string>("Mysql.Password");
            _mysql_schema = pt.get<std::string>("Mysql.Schema");
            _mysql_pool_size = pt.get<int>("Mysql.PoolSize", 5);
            _http_timeout = pt.get<int>("Http.Timeout", 60);
        }
        catch (const std::exception& e) {
            std::cerr << "Error: " << e.what() << std::endl;
            std::exit(1); // 结束程序并返回状态码1，表示程序遇到错误
        }
    }

    int _server_port{};
    int _server_pool_size{};
    std::string _redis_host;
    int _redis_port{};
    std::string _redis_password;
    int _redis_pool_size{};
    std::string _mysql_host;
    int _mysql_port{};
    std::string _mysql_user;
    std::string _mysql_password;
    std::string _mysql_schema;
    int _mysql_pool_size{};
    int _http_timeout{};

private:
    Config() = default;
};
